/*
 * @lc app=leetcode.cn id=1094 lang=golang
 * @lcpr version=30119
 *
 * [1094] 拼车
 */

// @lcpr-template-start

// @lcpr-template-end
// @lc code=start

func carPooling(trips [][]int, capacity int) bool {
	diff := make([]int, 1001)
	for _, trip := range trips {
		diff[trip[1]] += trip[0]
		diff[trip[2]] -= trip[0]
	}
	if diff[0] > capacity {
		return false
	}
	for i := 1; i < 1001; i++ {
		diff[i] += diff[i-1]
		if diff[i] > capacity {
			return false
		}
	}
	return true
}

// @lc code=end

/*
// @lcpr case=start
// [[2,1,5],[3,3,7]]\n4\n
// @lcpr case=end

// @lcpr case=start
// [[2,1,5],[3,3,7]]\n5\n
// @lcpr case=end

*/

